package com.tang.service.utils;

import com.tang.service.adapter.MediaAdapter;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class MediaUtil {

    public Map<String, String> mediaMap = new ConcurrentHashMap<>();

    public Map<String, MediaAdapter> mediaAdapterMap = new ConcurrentHashMap<>();

    public final String MP3 = "mp3";
    private static final String MP4 = "mp4";
    private static final String MP4_CLAZZ = "com.tang.service.impl.Mp4Player";
    private static final String VLC = "vlc";
    private static final String VLC_CLAZZ = "com.tang.service.impl.VlcPlayer";
    
    private static MediaUtil instance;

    private MediaUtil() {
        mediaMap.put(MP4, MP4_CLAZZ);
        mediaMap.put(VLC, VLC_CLAZZ);
    }

    public static MediaUtil getInstance() {
        if (null != instance) return instance;
        synchronized (MediaUtil.class) {
            if (null == instance) {
                instance = new MediaUtil();
            }
        }
        return instance;
    }
    
    public boolean containsAudioType(String audioType) {
        Set<String> strings = mediaMap.keySet();
        return strings.contains(audioType);
    }

    public MediaAdapter getMediaAdapter(String audioType) {
        return mediaAdapterMap.get(audioType);
    }
    
    public void setMediaAdapter(String audioType, MediaAdapter mediaAdapter) {
        mediaAdapterMap.put(audioType, mediaAdapter);
    }
    
}
